{include file="public/header" /}
        <div class="main-container ace-save-state" id="main-container">
            <script type="text/javascript">
                try{ace.settings.loadState('main-container')}catch(e){}
            </script>

            <div id="sidebar" class="sidebar responsive ace-save-state">
                <script type="text/javascript">
                    try{ace.settings.loadState('sidebar')}catch(e){}
                </script>
                {include file="public/menu" /} 

                <div class="sidebar-toggle sidebar-collapse" id="sidebar-collapse">
                    <i id="sidebar-toggle-icon" class="ace-icon fa fa-angle-double-left ace-save-state" data-icon1="ace-icon fa fa-angle-double-left" data-icon2="ace-icon fa fa-angle-double-right"></i>
                </div>
            </div>

            <div class="main-content">
                <div class="main-content-inner">
                    <div class="breadcrumbs ace-save-state" id="breadcrumbs">
                        <ul class="breadcrumb">
                            <li>
                                <i class="ace-icon fa fa-home home-icon"></i>
                                <a href="#">系统管理</a>
                            </li>
                            <li class="active">管理员列表</li>
                        </ul><!-- /.breadcrumb -->

                    </div>

                    <div class="page-content">
                        <div class="row">
                            <div class="col-xs-12">
                                <!-- PAGE CONTENT BEGINS -->
                                    <div class="tabbable">
                                        <ul class="nav nav-tabs padding-12 tab-color-blue background-blue" id="myTab">
                                            <li class="active">
                                                <a href="javascript:;">管理员列表</a>
                                            </li>
                                            <li>
                                                <a href="javascript:;" onclick="add_admin()">添加管理员</a>
                                            </li>
                                        </ul>
                                        <div class="tab-content">
                                            <table class="table table-striped table-bordered table-hover table-condensed">
                                                <tbody>
                                                    <tr>
                                                        <td class="center">ID</td>
                                                        <td>用户名</td>
                                                        <td>最近登录时间</td>
                                                        <td>登录次数</td>
                                                        <td>登录状态</td>
                                                        <td>创建时间</td>
                                                        <td>操作</td>
                                                    </tr>

                                                    {foreach $data as $vo}
                                                        <tr>
                                                            <td class="center">{$vo.id}</td>
                                                            <td>{$vo.account}</td>
                                                            <td>
                                                                {if condition="!empty($vo['login_time'])"}
                                                                    {$vo.login_time|date="Y-m-d H:i:s",###}
                                                                {/if}
                                                            </td>
                                                            <td>{$vo.login_count}</td>
                                                            <td>
                                                                {eq name="vo.status" value="1"}
                                                                <span class="label label-success label-white middle">允许</span>
                                                                {else/}
                                                                <span class="label label-danger label-white middle">锁定</span>
                                                                {/eq}
                                                            </td>
                                                            <td>{$vo.create_time|date="Y-m-d H:i:s",###}</td>
                                                            <td>
                                                                {neq name="vo.id" value="1"}
                                                                <a href="javascript:;" onclick="disable_admin({$vo['id']})">
                                                                    {eq name="vo.status" value="1"}锁定{else/}解禁{/eq}
                                                                </a> |
                                                                <a href="javascript:;" onclick="delete_admin({$vo['id']})">
                                                                    删除
                                                                </a> |
                                                                <a href="javascript:;" onclick="reset_admin({$vo['id']})">
                                                                    重置密码
                                                                </a>
                                                                {/neq}
                                                            </td>
                                                        </tr>
                                                    {/foreach}
                                                </tbody>
                                            </table>
                                        </div>
                                    </div>

                                <!-- PAGE CONTENT ENDS -->
                            </div><!-- /.col -->
                        </div><!-- /.row -->
                    </div><!-- /.page-content -->
                </div>
            </div><!-- /.main-content -->


            <a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
                <i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
            </a>
        </div><!-- /.main-container -->

        {include file="public/footer" /}
        <script type="text/javascript">
        // 管理员用户名规则验证
        function check_admin_username(name) { 
            var strlen = name.length; 
            var reg = /^[a-zA-Z0-9_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+$/;
            if (!reg.test(name)) { 
                return false; 
            }else if (10 < strlen || strlen < 5) { 
                return false; 
            }
            return true; 
        }

        // 添加管理员
        function add_admin(){
            layer.prompt({title: '请输入管理员用户名', formType: 3}, function(text, index){
                if(check_admin_username(text)) {
                    $.post("{:url('admin/administrator_add')}", { "account": $.trim(text)},function(data){
                        // console.log(data)
                        layer.close(index);
                        if(data.code) {
                            layer.confirm('该用户初始密码为：'+data.data, {
                                title:'管理员创建成功',
                                btn: ['确认'] //按钮
                            }, function(){
                                window.location.reload();
                            });
                        }else{
                            layer.msg(data.msg); 
                        }
                    }, "json");
                }else{
                    layer.msg('用户名不符合规则');
                }
            });
        }

        // 重置管理员密码
        function reset_admin(id){
            layer.confirm('确认重置管理员(ID:'+id+')的密码？', {
                btn: ['确认'] //按钮
            }, function(){
                var _index = layer.load(1, {
                  shade: [0.1,'#fff'] //0.1透明度的白色背景
                });

                $.post("{:url('admin/administrator_reset')}", { "id": id},function(data){
                    // console.log(data)
                    layer.close(_index);
                    if(data.code) {
                        layer.confirm('该用户重置密码为：'+data.data, {
                            title:'管理员密码重置成功',
                            btn: ['确认'] //按钮
                        }, function(){
                            // window.location.reload();
                            layer.closeAll();
                        });
                    }else{
                        layer.msg(data.msg); 
                    }
                }, "json");

            });
        }

        //删除管理员
        function delete_admin(id){
            layer.confirm('确定要删除管理员(ID:'+id+')吗？', {
                btn: ['确认','取消'], //按钮
                shade: 0.5 //显示遮罩
            }, function(){
                var _index = layer.load(1, {
                  shade: [0.1,'#fff'] //0.1透明度的白色背景
                });
                $.post("{:url('admin/administrator_delete')}", { "id": id},function(data){
                    // console.log(data)
                    layer.close(_index);
                    if(data.code){
                        layer.msg('删除成功', function(){
                                window.location.reload();
                            });
                    }else{
                        layer.msg(data.msg); 
                    }
                }, "json");
            },function(){
                // 取消删除操作
            });
        }

        //禁用／解禁用户
        function disable_admin(id){
            var _index = layer.load(1, {
              shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            $.post("{:url('admin/administrator_disable')}", { "id": id},function(data){
                // console.log(data)
                layer.close(_index);
                if(data.code){
                    layer.msg('操作成功', function(){
                        window.location.reload();
                    });
                }else{
                    layer.msg(data.msg); 
                }
            }, "json");
        }
               
        </script>
 
    </body>
</html>
